﻿using OrBitDataModule.Base;
using OrBitDataModule.CustomEventHandler;
using OrBitDataModule.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace OrBitDataScript
{
    public class Script : ScriptBase
    {
        /// <summary>
        /// 脚本加载事件
        /// </summary>
        public override void OnLoad()
        {

        }
        /// <summary>
        /// 启动开始后事件
        /// </summary>
        public async override void OnStarted()
        {
            await this.Context.Scheduler.AddTaskBySecond(3, new Action(() =>
             {
                 this.Context.TcpClientInstance.Send($"From script,{DateTime.Now.ToString()}");
             }));
            this.Context.Scheduler.Start();
        }
        /// <summary>
        /// 停止事件
        /// </summary>
        public override void OnStoped()
        {

        }
        /// <summary>
        /// 提交接口后事件
        /// </summary>
        /// <param name="result">返回结果</param>
        /// <param name="returnMessage">返回消息</param>
        /// <param name="outputResponse">相应消息，通常用于返回设备</param>
        public override void AfterSubmit(bool result, string returnMessage, string outputResponse)
        {

        }
        /// <summary>
        /// 提交接口前事件
        /// </summary>
        /// <param name="inputParameter">提交的参数</param>
        /// <param name="inputRequest">请求信息</param>
        public override void BeforeSubmit(InputParameter inputParameter, string inputRequest)
        {

        }

        /// <summary>
        /// 文件改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnFileSystem_Changed(object sender, ProcessedFileSystemEventArgs e)
        {

        }
        /// <summary>
        /// Http服务请求事件
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public override void OnHttpRequest(HttpListenerRequest request, HttpListenerResponse response)
        {

        }

        /// <summary>
        /// Socket数据接收事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void SocketClient_OnDataReceived(object sender, ReceivedDataEventArgs e)
        {

        }
        /// <summary>
        /// 串口数据接收事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void SerialPort_DataReceived(object sender, SerialPortReceivedEventArgs e)
        {
            string s = this.Context.DefaultEncoding.GetString(e.Data);
        }
        /// <summary>
        /// 销毁对象事件
        /// </summary>
        public override void OnDispose()
        {

        }
        /// <summary>
        /// 异常事件
        /// </summary>
        /// <param name="exception"></param>
        public override void OnError(Exception exception)
        {

        }
    }
}
